<script type="text/javascript">
function dialogAjaxDonecon(json){
	DWZ.ajaxDone(json);
	if (json.statusCode == DWZ.statusCode.ok){
			$.pdialog.open('__URL__/edit/id/'+{$vo.id},'contractedit',"修改", { max:false, mask:true, width: 540, height: 320});
		
	}
}
function change(value)
{
	var div1=document.getElementById('div1');
	var div2=document.getElementById('div2');
	var div3=document.getElementById('div3');
	if(value==''||value==null)
	{
		alert('请选择合同类型');
	}
	if(value=="1")
	{
		document.getElementById('div1').style.display='block';
		document.getElementById('div2').style.display='none';
		document.getElementById('div3').style.display='none';
	}
	if(value=="2")
	{
		document.getElementById('div2').style.display='block';
		document.getElementById('div1').style.display='none';
		document.getElementById('div3').style.display='none';
	}
	if(value=="3")
	{
		document.getElementById('div3').style.display='block';
		document.getElementById('div2').style.display='none';
		document.getElementById('div1').style.display='none';
	}
}

function setValue()
{
	var types=document.getElementsByName("type");
	for(var i=0;i<types.length;i++)
	{
		if(types[i].checked)
		{
			var index=types[i].value;
			var firstnames=document.getElementById('firstname'+index);
			var secondnames=document.getElementById('secondname'+index);
			
			var firstname=document.getElementById('firstname');
			var secondname=document.getElementById('secondname');
			firstname.value=firstnames.value;
			secondname.value=secondnames.value;
			
		}
	}
	
}

//中文逗号替换成英文逗号
function ReplaceDot()
{
     var Obj=document.getElementById('goodname');
     var oldValue=Obj.value;
     while(oldValue.indexOf("，")!=-1)//寻找每一个中文逗号，并替换
     {
         Obj.value=oldValue.replace("，",",");
         oldValue=Obj.value;
     }
}

</script>
<div class="pageContent">
	<form method="post" action="__URL__/update/navTabId/__MODULE__/callbackType/closeCurrent"  enctype="multipart/form-data" class="pageForm required-validate" onsubmit="return iframeCallback(this, dialogAjaxDone)">
		<input type="hidden" name="userid" value="<?php echo $_SESSION[C('USER_AUTH_KEY')] ?>">
		<input type="hidden" name="id" value="{$vo.id}" >
		<input type="hidden" name="firstname" id="firstname">
		<input type="hidden" name="secondname" id="secondname"> 
		<input type="hidden" name="ajax" value="1">
		<div class="pageFormContent" layoutH="188">
		 <!-- 
		 <div class="unit">
				<label style="margin-right: -40px;">选择合同类型：</label>
				<input type="radio" name="type"  value="1"<eq name="vo.type" value="1">checked</eq> onclick="change(this.value);"/>客户合同
				<input type="radio" name="type" value="2" <eq name="vo.type" value="2">checked</eq> onclick="change(this.value);"/>供应商合同
				<input type="radio" name="type"  value="3"  <eq name="vo.type" value="3">checked</eq> onclick="change(this.value);"/>承运商合同
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span><font color="red">请先选择合同类型</font></span>
		 </div>
		  -->
		 <div id="div1" style="display:{$div1}">
		    <p class="unit">
				<label >甲方：</label>
				<input type="text"   name="firstname"  id="firstname"  value="{$vo.firstname}" readonly="readonly"><span><font color="red">不可修改甲方</font></span>
				
			</p>
			<p class="unit" >
				<label>乙方：</label>
				<input type="text"   name="secondname"  id="secondname"  value="{$vo.secondname}" readonly="readonly"><span><font color="red">不可修改乙方</font></span>
			</p>
			</div>
			 <div id="div2" style="display:{$div2}">
		    <div class="unit">
				<label>甲方：</label>
				<input type="text"   name="secondname"  id="secondname" value="{$vo.secondname}" readonly="readonly"><input type="hidden" name="firstid"/><span><font color="red">不可修改甲方</font></span>
			</div>
			<p class="unit">
				<label >乙方：</label>
				<input type="text"   name="firstname"  id="firstname"  value="{$vo.firstname}" readonly="readonly"><span><font color="red">不可修改乙方</font></span>
			</p>
			</div>
			 <div id="div3" style="display:{$div3}">
		    <p class="unit">
				<label >甲方：</label>
				<input type="text"   name="firstname"  id="firstname"  value="{$vo.firstname}" readonly="readonly"><span><font color="red">不可修改甲方</font></span>
			</p>
			<p class="unit">
				<label>乙方：</label>
				<input type="text"   id="secondname" name="secondname"  value="{$vo.secondname}" readonly="readonly"><span><font color="red">不可修改乙方</font></span>
			</p>
			</div>
			<div class="unit">
				<label>乙方人：</label>
				<input type="text"   name="seconder" value="{$vo.seconder}">
			</div>
			<div class="unit">
				<label>乙方电话：</label>
				<input type="text"   name="secondphone" value="{$vo.secondphone}">
			</div>
			<div class="unit">
				<label>合同标题：</label>
				<input type="text"   name="subject"  value="{$vo.subject}">
			</div>
			<div class="unit">
				<label>合同编号：</label>
				<input type="text"   name="contractno" value="{$vo.contractno}">
			</div>
			<!--
			<div class="unit">
				<label>商品名称：</label>
				<input type="hidden"   name="goodid">
				<input type="text"  name="goodname"  id="goodname" onkeyup="ReplaceDot();" value="{$vo.goodname}"><a class="btnLook" href="__URL__/getgoods" lookupGroup="">查找带回</a><span><font color="red">输入多个商品名称，请用逗号隔开</font></span>
			</div>
			  
			<div class="unit">
				<label>商品类型：</label>
				<input type="text"   name="goodtype"  value="{$vo.goodtype}">
			</div>
			
			<div class="unit">
				<label>购买数量：</label>
				<input type="text" class="number" id="quality" name="quality" value="{$vo.quality}" onblur="setVal();" onkeydown="hideText();">
			</div>	
			<div class="unit">
				<label>产品单价/吨：</label>
				<input type="text" class="number"  id="price" name="price"   value="{$vo.price}" onblur="setVal();">
			</div>
			-->
			<script type="text/javascript">
			function setVal() {
				//var quality=document.getElementById('quality').value;
				var totalprice = document.getElementById('totalprice');
				var price = document.getElementById('price');
				var quality = document.getElementById('quality');
				//totalprice.value=quality*price;
				if(totalprice.value!=null&&totalprice.value!=""&&price.value!=null&&price.value!="")
				{
				  quality.value = totalprice.value / price.value;
				}
				else if(quality.value!=null&&quality.value!=""&&price.value!=null&&price.value!="")
				{
					totalprice.value=quality.value*price.value;
					
				}
			}
			function hideText()
			{
				document.getElementById('totalprice').value="";
			}
			</script>
			<div class="unit">
				<label>提货周期：</label>
				<input type="text" name="deadline" class="date" value="{$vo.deadline}"><a class="inputDateButton" href="javascript:;" style="">选择</a>
			    <label>至：</label>
				<input type="text" name="deadlined" class="date" value="{$vo.deadlined}"><a class="inputDateButton" href="javascript:;" style="">选择</a>
			</div>
			<div class="unit">
				<label>主要条款：</label>
				<textarea rows="3" cols="56" style="width: 360px;" name="mainitem">{$vo.mainitem}</textarea>
			</div>
			<div class="unit">
				<label>售后条款：</label>
				<textarea rows="3" cols="56" style="width: 360px;" name="salesafteritem">{$vo.salesafteritem}</textarea>
			</div>
			<div class="unit">
				<label>生效日期：</label>
				<input type="text" name="validdae" value="{$vo.validdae}" class="date"/><a class="inputDateButton" href="javascript:;">选择</a>
			</div>
			<div class="unit">
				<label>有效截止日期：</label>
				<input type="text" name="expiredate" value="{$vo.expiredate}" class="date"><a class="inputDateButton" href="javascript:;" >选择</a>
			</div>
			<div class="unit">
				<label>签约人：</label>
				<input type="text" name="signupuser" value="{$vo.signupuser}">
			</div>
			<div class="unit">
				<label>签约时间：</label>
				<input type="text" name="signuptime" value="{$vo.signuptime}" class="date"/><a class="inputDateButton" href="javascript:;">选择</a>
			</div>
			<div class="unit">
				<label>合同来源：</label>
			    <eq name="vo.projectid" value="0">
			    <input type="hidden"  name="projectid"  value="{$vo.projectid}"/>
			    <input type="hidden"  name="businesstype"  value="{$vo.businesstype}"/>
			    <input type="text"  name="project"  value="投标合同">
			    <a class="btnLook" href="__URL__/search"  lookupGroup="" >查找带回</a>
			    <else/>
			  
			    <input type="hidden"  name="projectid" value="{$vo.projectid}"/>
			      <input type="hidden"  name="businesstype" value="{$vo.businesstype}"/>
			    <input type="text" name="project"  readonly value="{$vo.businesstype}">
			    <a class="btnLook" href="__URL__/search"  lookupGroup="" >查找带回</a>
			    <a  href="__URL__/lookup/id/{$vo.projectid}"  style="float:left" rel="look"  mask="true" target="dialog">
			    <button>查看</button>
			    </a>
			    </eq>
			</div>
			<div class="unit">
				<label>收货地址：</label>
				<input type="text" name="consignaddress" value="{$vo.consignaddress}" style="width: 360px;">
			</div>
			<div class="unit">
				<label>收货人：</label>
				<input type="text" name="consignee" value="{$vo.consignee}">
			</div>
			<div class="unit">
				<label>结算方式：</label>
				<input type="text" name="clearform" value="{$vo.clearform}">
			</div>
			</div>
			
			<!-- 
			<div class="unit">
			<input type="hidden" name="fileids"/>
					<label style="width: 70px;">修改照片：</label> <input type="file" name="file" style="height: 21px;"/>
				</div>
				<eq name="{filename}" value="">
				<else/>
				<div class="unit" >
					<img style="margin-left:30%" width="200" height="200"  src="__PUBLIC__/{$filename}"/>
                </div>
                </eq> -->
		
		<div width="100%"  layoutH="290">
		<table class="list nowrap itemDetail" addButton="新增商品" width="100%">
						<thead>
							<tr>
							 <th type="lookup" name="items.org.goodname[#index#]" lookupGroup="items.org"   suggestFields="goodid,goodname"   lookupUrl="__URL__/getgoods" lookupPk="goodid"  size="12"  >商品名称</th>
			                 <th type="text" name="items.itemQuality[#index#]" size="12" fieldClass="number" >购买数量</th>
			                 <th type="text" name="items.itemPrice[#index#]" size="12" fieldClass="number"  >产品单价/吨</th>
			                 <th type="text" name="items.itemTotalprice[#index#]" size="12" fieldClass="number"  >金额</th>
		                     <th type="del" width="60">操作</th>
		                    </tr>
						</thead>
						<tbody>
						</tbody>
			</table>
			<table  width="100%">
			           <thead>
							<tr>
							 <th>-</th>
			                  <th>-</th>
			                  <th>-</th>
			                 <th>-</th>
		                     <th>-</th>
		                    </tr>
						</thead>
					<tbody>
						<volist id="con" name="cg">
						<tr target="sid_good" rel="{$con['id']}">
						<input type="hidden" name="goodid[]"  value = "{$con['id']}" />
						<td><input type="text" size = '12' name="goodname[]" value="{$con['goodname']}" /></td>
						<td><input type="text" size = '12' name="quality[]" value="{$con['quality']}"/></td>
						<td><input type="text" size = '12' name="price[]" value="{$con['price']}"/></td>
						<td><input type="text" size = '12' name="totalprice[]" value="{$con['totalprice']}"/></td>
						<td><a class="delete"
						href="__URL__/gooddelete/conid/{$con['id']}/navTabId/edit"
						target="ajaxTodo" callback="dialogAjaxDonecon"title="你确定要删除吗？"><button>删除</button></a>
						</td>
						</tr>
						</volist>
					</tbody>
			</table>
		</div>
		<div class="formBar">
			<ul>
				<li><div class="buttonActive"><div class="buttonContent"><button type="submit" onclick="setValue();">保存</button></div></div></li>
				<li><div class="button"><div class="buttonContent"><button type="button" class="close">取消</button></div></div></li>
			</ul>
		</div>
	</form>

</div>

